home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group95b.txt
/
000038_icon-group-sender _Wed Jun 7 04:46:24 1995.msg
< prev
next >
Wrap
Internet Message Format
|
1995-09-18
|
3KB
Received: by cheltenham.cs.arizona.edu; Wed, 7 Jun 1995 08:20:57 MST
From: Nevin Liber <nevin@lectura>
Message-Id: <199506071147.EAA10758@lectura.CS.Arizona.EDU>
Subject: Re: Garbage collection vs files
To: davidf@deci.mks.com (David J. Fiander)
Date: Wed, 7 Jun 1995 04:46:24 -0700 (MST)
Cc: icon-group-l@cs.arizona.edu
In-Reply-To: <3qr2a1$afq@deci.mks.com> from "David J. Fiander" at Jun 3, 95 09:29:37 pm
X-Mailer: ELM [version 2.4 PL23]
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Length: 2227
Sender: nevin@lectura
Errors-To: icon-group-errors@cs.arizona.edu
davidf@deci.mks.com (David J. Fiander) writes:
> Most lisps will properly close files during garbage collection.
> Does iconx, or the code generated by iconc?
No. I'm not sure why you would want to. I can see doing it under
LISP, since there is usually an interactive programming environment
associated with it. There is no such environment associated with
Icon.
Also, closing open files at garbage collection time is not correct
semantically speaking, since the program itself might be dependent on
the underlying file system semantics. For instance, on a local Unix
disk (this is also hacked into NFS, but I digress), one is allowed to
open a file and then remove it (technically, remove its directory
entry), and still access the file until it is closed or the program
terminates. This is guaranteed for a Unix filesystem, and closing an
open file descriptor at garbage collection time would break these semantics.
(One could argue that one should not be dependent on tricks like this, but
that is beyond the scope of this discussion.)
On a related note: whenever I write a tool that takes a bunch of file
names from the command line, or reads from &input if none are
specified, I use a variation of the following routine:
procedure InputFiles(LInputFilenames[])
local sFilename
local fInput
if 0 = *LInputFilenames then {
return &input
}
while sFilename := get(LInputFilenames) do {
if not (fInput := open(string(sFilename))) then {
write(&errout, &progname, ": cannot open ", image(sFilename),
" for reading.")
next
}
suspend fInput
close(fInput)
}
end
And the caller looks something like:
procedure main(LArguments)
local fFile
...
every fFile := InputFiles ! LArguments do {
ProcessFile(fFile)
}
This way, I am sure to close all the files that I open, I don't close
&input (I don't like to close files that I didn't open), and all the
code to handle the case where there are no files specified on the
command line is isolated to InputFiles().
--
Nevin ":-)" Liber nevin@cs.arizona.edu (520) 293-2799
office: (520) 621-1815